package com.sctvcloud.zhaohua_sd.ui.adapter.holder;

import android.content.Context;
import android.text.TextUtils;
import android.util.Log;
import android.view.View;
import android.widget.LinearLayout;

import com.ruihang.generalibrary.ui.adapter.holder.BaseRecylerHolder;
import com.ruihang.generalibrary.ui.widget.CustomEXImageView;
import com.ruihang.generalibrary.ui.widget.CustomFontTextView;
import com.ruihang.generalibrary.utils.DateUtils;
import com.sctvcloud.zhaohua_sd.R;
import com.sctvcloud.zhaohua_sd.beans.ADynamicsItem;
import com.sctvcloud.zhaohua_sd.beans.GovItemBean;
import com.sctvcloud.zhaohua_sd.beans.NewsItem;
import com.sctvcloud.zhaohua_sd.ui.utils.GlideCircleTransform;
import com.sctvcloud.zhaohua_sd.ui.utils.GlideUtil;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;

/**
 * Created by Administrator on 2017/7/17 0017.
 */

public class GovStuffHolder extends BaseRecylerHolder<GovItemBean> implements View.OnClickListener {
    @BindView(R.id.item_city_state_news_img)
    protected CustomEXImageView img;
    @BindView(R.id.item_city_state_news_title)
    protected CustomFontTextView title;
    @BindView(R.id.item_city_state_news_img_2)
    protected CustomEXImageView img_2;
    @BindView(R.id.item_city_state_news_title_2)
    protected CustomFontTextView title_2;
    @BindView(R.id.item_city_state_channel_icon)
    protected CustomEXImageView icon;

    @BindView(R.id.item_city_state_channel_name)
    protected CustomFontTextView item_city_state_channel_name;

    @BindView(R.id.li_one)
    protected LinearLayout li_one;
    @BindView(R.id.li_two)
    protected LinearLayout li_two;
    @BindView(R.id.li_all)
    protected LinearLayout li_all;

    @BindView(R.id.item_city_state_channel_status)
    protected CustomFontTextView item_city_state_channel_status;
    private GovItemBean item;

    public GovStuffHolder(Context context, View itemView) {
        super(context, itemView);
        itemView.setOnClickListener(this);
        li_one.setOnClickListener(this);
        li_two.setOnClickListener(this);
        li_all.setOnClickListener(this);
        item_city_state_channel_status.setOnClickListener(this);
    }

    @Override
    protected void initInject() {
        ButterKnife.bind(this, itemView);
    }

    @Override
    public void setData(GovItemBean item) {
        this.item = item;

        if (!TextUtils.isEmpty(item.getInstitutionName())) {
            item_city_state_channel_name.setText(item.getInstitutionName());
        }
        GlideUtil.getGlid(context, item.getInstitutionImage()).error(R.mipmap.icon_circle_avatar)
                .placeholder(R.mipmap.icon_circle_avatar).transform(new GlideCircleTransform(context))
                .into(icon);

        item_city_state_channel_status.setBackgroundResource(item.isSubscibe() ? R.drawable.ucrop_bg_cv_red : R.drawable.bg_look_back);
        item_city_state_channel_status.setText(item.isSubscibe() ? context.getString(R.string.city_state_subscribe) : context.getString(R.string.city_state_no_subscribe));
        item_city_state_channel_status.setTextColor(item.isSubscibe() ? context.getResources().getColor(R.color.white) : context.getResources().getColor(R.color.blue_main));


        if (null != item.getInfoList()) {
            if (item.getInfoList().size() == 0) {
                img.setVisibility(View.GONE);
                title.setVisibility(View.GONE);
                img_2.setVisibility(View.GONE);
                title_2.setVisibility(View.GONE);
            } else if (item.getInfoList().size() == 1) {
                GlideUtil.getGlideWithSmall169Def(context, item.getInfoList().get(0).getNewsImage()).into(img);
                img.setVisibility(View.VISIBLE);
                if (!TextUtils.isEmpty(item.getInfoList().get(0).getNewsTitle())) {
                    title.setVisibility(View.VISIBLE);
                    title.setText(item.getInfoList().get(0).getNewsTitle());
                }

                img_2.setVisibility(View.GONE);
                title_2.setVisibility(View.GONE);


            } else if (item.getInfoList().size() >= 2) {
                GlideUtil.getGlideWithSmall169Def(context, item.getInfoList().get(0).getNewsImage()).into(img);
                img.setVisibility(View.VISIBLE);
                if (!TextUtils.isEmpty(item.getInfoList().get(0).getNewsTitle())) {
                    title.setVisibility(View.VISIBLE);
                    title.setText(item.getInfoList().get(0).getNewsTitle());
                }

                GlideUtil.getGlideWithSmall169Def(context, item.getInfoList().get(1).getNewsImage()).into(img_2);
                img_2.setVisibility(View.VISIBLE);
                if (!TextUtils.isEmpty(item.getInfoList().get(1).getNewsTitle())) {
                    title_2.setVisibility(View.VISIBLE);
                    title_2.setText(item.getInfoList().get(1).getNewsTitle());
                }

            } else {

            }
        }


    }

    @Override
    public void onClick(View v) {
        if (v.getId() == R.id.li_one) {
            if (internalClick != null) {
                li_one.setTag(R.id.adapter_item_data_key, item.getInfoList().get(0));
                internalClick.onItemInternalClick(li_one, v, getAdapterPosition());
            }
        } else if (v.getId() == R.id.li_two) {
            if (internalClick != null) {
                li_two.setTag(R.id.adapter_item_data_key, item.getInfoList().get(1));
                internalClick.onItemInternalClick(li_two, v, getAdapterPosition());
            }
        }

        if (v.getId() == R.id.li_all) {
            if (internalClick != null) {
                li_all.setTag(R.id.adapter_item_data_key, item);
                internalClick.onItemInternalClick(li_all, v, getAdapterPosition());
            }
        } else if (v.getId() == R.id.item_city_state_channel_status) {
            if (internalClick != null) {
                item_city_state_channel_status.setTag(R.id.adapter_item_data_key, item);
                internalClick.onItemInternalClick(item_city_state_channel_status, v, getAdapterPosition());
            }
        }


    }


}
